using System;
using System.Data.Linq;
using System.Linq;
using InfoTech.Core.Data.SqlClient;
using InfoTech.Core.Service;
using InfoTech.LanTranh.MucVu.Bussiness;

namespace InfoTech.LanTranh.MucVu.Service
{
    public class SOHONNHANService : BaseService
    {

        public static bool Check_Insert_SOHONNHAN(Bussiness.SOHONNHAN sohonnhan)
        {
            bool result = true;
            DataContext dataContext = CreateDataContext();
            if (sohonnhan.PRT_GIAODAN_CHONG.IsPersistence)
                result &=
                    dataContext.GetTable<SOHONNHAN>().Where(
                        c => c.MAGIAODAN_CHONG == sohonnhan.MAGIAODAN_CHONG && c.LYHON != true && c.MAHONNHAN != sohonnhan.MAHONNHAN).FirstOrDefault() == null;
            if (sohonnhan.PRT_GIAODAN_VO.IsPersistence)
                result &=
                    dataContext.GetTable<SOHONNHAN>().Where(
                        c => c.MAGIAODAN_VO == sohonnhan.MAGIAODAN_VO && c.LYHON != true && c.MAHONNHAN != sohonnhan.MAHONNHAN).FirstOrDefault() == null;
            return result;
        }

        public static bool Check_Update_SOHONNHAN(SOHONNHAN sohonnhan)
        {
            return true;
        }

        public static bool Check_Delete_SOHONNHAN(string[] strings)
        {
            return true;
        }

        public static void Delete(SOHONNHAN sohonnhan)
        {

        }

        public static void Delete(GIAODAN giaodan)
        {
            foreach (SOHONNHAN sohonnhan in giaodan.REF_SOHONNHAN)
            {
                sohonnhan.DeletebyId();
            }
        }
    }
}
